/*******************************************************************************
 * Copyright (c) 2006 CEA LIST.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA LIST - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.activitydiagram.tabbedproperties.section;

import org.eclipse.uml2.uml.InputPin;
import org.eclipse.uml2.uml.NamedElement;
import org.eclipse.uml2.uml.SendSignalAction;
import org.eclipse.uml2.uml.Type;
import org.eclipse.uml2.uml.TypedElement;
import org.eclipse.uml2.uml.UMLFactory;

import com.cea.papyrus.core.filters.TypeFilter;
import com.cea.papyrus.core.tabbedproperties.AbstractSelectionElementSection;

/**
 * 
 */
public class TargetSendSignalActionSection extends AbstractSelectionElementSection {


	public TargetSendSignalActionSection() {
		super("target", new TypeFilter());
		// TODO Auto-generated constructor stub
	}


	@Override
	public NamedElement getReferencedElementToDisplay() {
		TypedElement target = ((SendSignalAction)umlElement).getTarget();
		if(target!=null){
		return target.getType();}
		return null;
	}

	@Override
	public void removeReferencedElement() {
		((SendSignalAction)getElement()).setTarget(null);
		
	}

	@Override
	public void setReferencedElement(NamedElement element) {
		if (element instanceof Type){
			Type type = (Type)element; 
			if(type!= null){
				InputPin target=UMLFactory.eINSTANCE.createInputPin();
				target.setName(type.getName().toLowerCase());
				target.setType(type);
			 	((SendSignalAction)getElement()).setTarget(target);
			}
		}
		
	}
}